/**
 * 通行日志管理初始化
 */
var ActionLog = {
    id: "ActionLogTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ActionLog.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {
            title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {


                var a = "";
                if (row.log_type == "异常通行记录") {
                    var a = '<span style="color: #0089ff">' + value + '</span>';
                    return a;
                }else {
                    var a = '<span class="value">' + value + '</span>';
                    return a;
                }
            }
        },
            {title: '车牌号', field: 'car_number', visible: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {

                    var a = "";
                    if (row.log_type == "异常通行记录") {
                        var a = '<span style="color: #0089ff">' + value + '</span>';
                        return a;
                    }
                    else {
                        var a = '<span class="value">' + value + '</span>';
                        return a;
                    }
                }
            },
            {title: '通行时间', field: 'io_time', visible: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {

                    var a = "";
                    if (row.log_type == "异常通行记录") {
                        var a = '<span style="color: #0089ff">' + value + '</span>';
                        return a;
                    } else {
                        var a = '<span class="value">' + value + '</span>';
                        return a;
                    }
                }
            },
            {title: '通道号', field: 'channel_id', visible: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {

                    var a = "";
                    if (row.log_type == "异常通行记录") {
                        var a = '<span style="color: #0089ff">' + value + '</span>';
                        return a;
                    }else {
                        var a = '<span class="value">' + value + '</span>';
                        return a;
                    }
                }
            },
            {title: '方向', field: 'direction', visible: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {

                    var a = "";
                    if (row.log_type == "异常通行记录") {
                        var a = '<span style="color: #0089ff">' + value + '</span>';
                        return a;
                    } else {
                        var a = '<span class="value">' + value + '</span>';
                        return a;
                    }
                }
            },
            {title: '日志类型', field: 'log_type', visible: true, align: 'center', valign: 'middle',formatter: function (value, row, index) {
                    if (row.log_type == "正常通行记录") {
                        return '<span class="value" >正常通行记录</span>';
                    } else {
                        return '<span style="color:#0089ff" >异常通行记录</span>';
                    }

                }

            },
        {
            title: '备注',
            field: 'remark',
            visible: true,
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {

                var a = "";
                if (row.log_type == "异常通行记录") {
                    var a = '<span style="color: #0089ff">' + value + '</span>';
                    return a;
                } else {
                    var a = '<span class="value">' + value + '</span>';
                    return a;
                }
            }
        }
    ];
};

/**
 * 检查是否选中
 */
ActionLog.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ActionLog.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加通行日志
 */
ActionLog.openAddActionLog = function () {
    var index = layer.open({
        type: 2,
        title: '添加通行日志',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/actionLog/actionLog_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看通行日志详情
 */
ActionLog.openActionLogDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '修改通行日志',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/actionLog/actionLog_update/' + ActionLog.seItem.id
        });
        this.layerIndex = index;
    }
};

ActionLog.detail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '通行日志详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/actionLog/actionLog_detail/' + ActionLog.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除通行日志
 */
ActionLog.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/actionLog/delete", function (data) {
            Feng.success("删除成功!");
            ActionLog.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("actionLogId",this.seItem.id);
        ajax.start();
    }
};

ActionLog.delLog = function () {
    Feng.confirm("是否清空所有日志?",function(){
        var ajax = Feng.baseAjax("/actionLog/delLog","清空日志");
        ajax.start();
        ActionLog.table.refresh();
    });
}

ActionLog.download = function() {
     var queryData=ActionLog.formParams();
      /*var ajax = new $ax(Feng.ctxPath + "/actionLog/testParm", function (data) {
                 Feng.success("运行成功!");
             });
        ajax.set("carNumber",queryData.carNumber);
        ajax.set("logType",queryData.logType);
        ajax.start();*/
        window.location.href="/actionLog/testParm?carNumber="+queryData.carNumber;
     //window.location.href="/actionLog/download";
}

ActionLog.formParams = function() {
    var queryData = {};

    queryData['carNumber'] = $("#carNumber").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    queryData['logType'] = $("#logType").val();

    return queryData;
}

/**
 * 查询通行日志列表
 */
ActionLog.search = function () {
    ActionLog.table.refresh({query: ActionLog.formParams()});
};

$(function () {
    var defaultColunms = ActionLog.initColumn();
    var table = new BSTable(ActionLog.id, "/actionLog/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(ActionLog.formParams());
    ActionLog.table = table.init();
});
